package h0910;

import java.util.HashMap;

/**
  * @description 最长和谐子序列
  * @author 不知名帅哥
  * @date 2024/9/10 22:13
  * @version 1.0
*/
public class LongestHarmonySubSequence {
    public static void main(String[] args) {

    }
    public int findLHS(int[] nums) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            map.put(num,map.getOrDefault(num,0)+1);
        }
        int maxLen=0;
        for (Integer key : map.keySet()) {
            if (map.containsKey(key+1)){
                maxLen=Math.max(maxLen,map.get(key)+map.get(key+1));
            }
        }
        return maxLen;
    }
}
